/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dnl.math.graph2d.fol;

import javax.swing.JSlider;

import dnl.util.ui.WindowUtils;

/**
 *
 * @author daniel
 */
public class FolFrame extends javax.swing.JFrame {

	private FolCanvas folCanvas;

	/**
	 * Creates new form FolFrame
	 */
	public FolFrame() {
		initComponents();
		folCanvas = new FolCanvas();
		getContentPane().add(folCanvas, java.awt.BorderLayout.CENTER);
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        nSlider = new javax.swing.JSlider();
        levelsSlider = new javax.swing.JSlider();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        radiusSlider = new javax.swing.JSlider();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Ayelet's Garden");
        setBackground(new java.awt.Color(244, 242, 238));

        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        jPanel1.setPreferredSize(new java.awt.Dimension(773, 228));

        nSlider.setMajorTickSpacing(4);
        nSlider.setMaximum(30);
        nSlider.setMinimum(1);
        nSlider.setMinorTickSpacing(1);
        nSlider.setPaintLabels(true);
        nSlider.setPaintTicks(true);
        nSlider.setSnapToTicks(true);
        nSlider.setValue(6);
        nSlider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                nSliderStateChanged(evt);
            }
        });

        levelsSlider.setMaximum(5);
        levelsSlider.setMinimum(1);
        levelsSlider.setMinorTickSpacing(1);
        levelsSlider.setPaintLabels(true);
        levelsSlider.setPaintTicks(true);
        levelsSlider.setSnapToTicks(true);
        levelsSlider.setValue(2);
        levelsSlider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                levelsSliderStateChanged(evt);
            }
        });

        jLabel1.setText("n :");

        jLabel2.setText("Levels: ");

        radiusSlider.setMajorTickSpacing(50);
        radiusSlider.setMaximum(200);
        radiusSlider.setMinorTickSpacing(10);
        radiusSlider.setPaintLabels(true);
        radiusSlider.setPaintTicks(true);
        radiusSlider.setSnapToTicks(true);
        radiusSlider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                radiusSliderStateChanged(evt);
            }
        });

        jLabel3.setText("Radius (pix) :");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(jLabel1)
                .addGap(93, 93, 93)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(radiusSlider, javax.swing.GroupLayout.DEFAULT_SIZE, 374, Short.MAX_VALUE)
                    .addComponent(nSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(94, 94, 94)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(levelsSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(41, 41, 41))
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(22, 22, 22)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(718, Short.MAX_VALUE)))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(49, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(33, 33, 33))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(nSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(20, 20, 20))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(levelsSlider, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(radiusSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(25, 25, 25))
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                    .addContainerGap(182, Short.MAX_VALUE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(16, 16, 16)))
        );

        getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_END);

        pack();
    }// </editor-fold>//GEN-END:initComponents

	private void nSliderStateChanged(final javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_nSliderStateChanged
		JSlider source = (JSlider) evt.getSource();
		if (!source.getValueIsAdjusting()) {
			int n = source.getValue();
			folCanvas.setArcNum(n);
			folCanvas.recalcPoints();
		}
	}//GEN-LAST:event_nSliderStateChanged

	private void levelsSliderStateChanged(final javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_levelsSliderStateChanged
		JSlider source = (JSlider) evt.getSource();
		if (!source.getValueIsAdjusting()) {
			int levels = source.getValue();
			folCanvas.setLevels(levels);
			folCanvas.recalcPoints();
		}
	}//GEN-LAST:event_levelsSliderStateChanged

	private void radiusSliderStateChanged(final javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_radiusSliderStateChanged
		JSlider source = (JSlider) evt.getSource();
		if (!source.getValueIsAdjusting()) {
			int r = source.getValue();
			folCanvas.setRadius(r);
			folCanvas.recalcPoints();
		}
	}//GEN-LAST:event_radiusSliderStateChanged

	@Override
	public void setVisible(final boolean visible){
		super.setVisible(visible);
		folCanvas.setArcNum(nSlider.getValue());
		folCanvas.setRadius(radiusSlider.getValue());
		folCanvas.setLevels(levelsSlider.getValue());
		folCanvas.recalcPoints();
	}

	/**
	 * @param args the command line arguments
	 */
	public static void main(final String args[]) {
		/*
		 * Set the Nimbus look and feel
		 */
		//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
		/*
		 * If Nimbus (introduced in Java SE 6) is not available, stay with the
		 * default look and feel. For details see
		 * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
		 */
		try {
			for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
				if ("Nimbus".equals(info.getName())) {
					javax.swing.UIManager.setLookAndFeel(info.getClassName());
					break;
				}
			}
		} catch (ClassNotFoundException ex) {
			java.util.logging.Logger.getLogger(FolFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (InstantiationException ex) {
			java.util.logging.Logger.getLogger(FolFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (IllegalAccessException ex) {
			java.util.logging.Logger.getLogger(FolFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (javax.swing.UnsupportedLookAndFeelException ex) {
			java.util.logging.Logger.getLogger(FolFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		}
		//</editor-fold>

		/*
		 * Create and display the form
		 */
		java.awt.EventQueue.invokeLater(new Runnable() {

			@Override
			public void run() {
				FolFrame f = new FolFrame();
				WindowUtils.setWindowSize(f, .5, .7);
				WindowUtils.centerWindow(f);
				f.setVisible(true);
			}
		});
	}
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JSlider levelsSlider;
    private javax.swing.JSlider nSlider;
    private javax.swing.JSlider radiusSlider;
    // End of variables declaration//GEN-END:variables
}
